<?php 
class App_Page_Pager_AdminPage extends Main_Pager
{
	/**
	 * @var array
	 */
	protected $_fields = array(
		'id'   => array('simpleSearch' => true, 'sql' => 'page.id'),
		'level'   => array('simpleSearch' => true, 'sql' => 'page.level'),
		'lft'   => array('simpleSearch' => true, 'sql' => 'page.lft'),
		'page_name' => array('simpleSearch' => true, 'sql' => 'page_object.name'),
		'layout_name' => array('simpleSearch' => true, 'sql' => 'layout_i18n.title'),
		'parent_id' => array('simpleSearch' => true, 'sql' => 'page.parent_id'),
		'f_active'  => array('simpleSearch' => true, 'sql' => 'page_object.f_active'),	
	);
	
	/**
	 * @return void
	 */
	protected function _init()
	{
		$this->_config['base'] = "
			SELECT 
				page.id
				, page.level
				, page_object.name as page_name 
				, layout_i18n.title as layout_name
				, page_object.f_map
				, page_object.f_active
			FROM
				page
			INNER JOIN
				page_object
				ON
					(page.id=page_object.page_id)
			INNER JOIN
				layout
				ON		
					(page_object.layout_id=layout.id)
			INNER JOIN
				layout_i18n
				ON		
					(layout_i18n.layout_id=layout.id)					
			INNER JOIN
				page_i18n
				ON
					(page.id=page_i18n.page_id AND page_i18n.lang_id={$this->_langId})
			WHERE true		
		";
				
		$this->_config['count'] = "
			SELECT 
				COUNT(page.id)
			FROM
				page
			INNER JOIN
				page_object
				ON
					(page.id=page_object.page_id)
			INNER JOIN
				layout
				ON		
					(page_object.layout_id=layout.id)
			INNER JOIN
				layout_i18n
				ON		
					(layout_i18n.layout_id=layout.id)					
			INNER JOIN
				page_i18n
				ON
					(page.id=page_i18n.page_id AND page_i18n.lang_id={$this->_langId})
			WHERE true	
		";		

		$this->_service = new App_Page_Service_Page();
						
		parent::_init();			
	}
	
	/**
	 * @param int|string $primary
	 * @return bool
	 */
	protected function _deleteItem($primary) 
	{
		return $this->_service->deleteItem($primary);
	}
}


